/********************************************************************
	copyright (c) by tnmujoy
    @created:	9/19/2011   15:11
    @filename: 	console
    @author:	Limiko Lau (limiko.lau@gmail.com)
    @brief:	    
*********************************************************************/

#ifndef GDUT_CONSOLE_H_
#define GDUT_CONSOLE_H_

#include <io.h>   
#include <fcntl.h>   
#include <iostream>   

#if defined(_WIN32)
#include "winConsole.hxx"
#endif

namespace tnmujoy
{
namespace gdut
{

class TConsole
{
public:
    static const int SUCCEEDED = 0;
    TConsole()
        : consoleImpl_(NULL)
    {

    }

    ~TConsole()
    {
        if (consoleImpl_)
        {
            consoleImpl_->free();
            delete consoleImpl_;
            consoleImpl_ = NULL;
        }

    }

    inline std::string error() const
    {
        if (consoleImpl_)
            return consoleImpl_->error();
        return "";
    }

    inline int exec(bool _withScript = false)
    {
#if defined(_WIN32)
        consoleImpl_ = new TWinConsoleImpl();
#endif
        return consoleImpl_->run(_withScript);
    }
protected:
private:
    TConsoleInterface* consoleImpl_;
};

}//namespace gdut
}//namespace tnmujoy

#endif //GDUT_CONSOLE_H_

//
//History:
//[9/19/2011] <limiko.lau@gmail.com> created